<template>
    <h1>用户详细信息页面</h1>

    <table>

        <tr>
            <td>真实姓名</td>
            <td>
                <input type="text" v-model="info.UI_Name" >
            </td>
        </tr>

        <tr>
            <td>性别</td>
            <td>
                <input type="radio" name="sex" v-model="info.UI_Sex" value="男" >男
                <input type="radio" name="sex" v-model="info.UI_Sex" value="女">女
            </td>
        </tr>

        <tr>
            <td>身份证号</td>
            <td>
                <input type="text" v-model="info.UI_Cord">
            </td>
        </tr>

        <tr>
            <td>出生时间</td>
            <td>
                <input type="date" v-model="info.UI_Date" >
            </td>
        </tr>

        <tr>
            <td>联系方式</td>
            <td>
                <input type="text" v-model="info.UI_Phone" >
            </td>
        </tr>

        <tr>
            <td>年收益</td>
            <td>
                <input type="text" v-model="info.UI_Money">
            </td>
        </tr>

        <tr>
            <td>用户类型</td>
            <td>
                <select v-model="info.UT_Id" >
                    <option value="0">请选择</option>
                    <option v-for="item in Type" :key="item.UT_Id" :value="item.UT_Id" >
                        {{ item.UT_Name }}
                    </option>
                </select>
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="用户详细信息添加" @click="UserInfoAdd">
            </td>
        </tr>

    </table>


</template>

<script setup lang="ts">

import { useRoute } from 'vue-router'
import { ref,onMounted } from 'vue'
import axios from 'axios';

const Type = ref([{
    UT_Id:'',
    UT_Name:'',
}])

const info = ref({
    U_Id:'',
    UI_Name:'',
    UI_Sex:'',
    UI_Cord:'',
    UI_Date:'',
    UI_Phone:'',
    UI_Money:'',
    UT_Id:0,
})

const route = useRoute();

console.log(route.params.U_Id);

onMounted (()=>{
    axios({
        url:'http://localhost:64202/api/User/ShowUserType',
        method:'get',
    })
    .then((res)=>{
        console.log(res.data);
        Type.value = res.data;
    })
    .catch((err)=>{
        console.log(err);
    })

})

const UserInfoAdd = ()=>{
    axios({
        url:'http://localhost:64202/api/User/UserInfoAdd',
        method:'post',
        data:{
            U_Id:route.params.U_Id,
            UI_Name:info.value.UI_Name,
            UI_Sex:info.value.UI_Sex,
            UI_Cord:info.value.UI_Cord,
            UI_Date:info.value.UI_Date,
            UI_Phone:info.value.UI_Phone,
            UI_Money:info.value.UI_Money,
            UT_Id:info.value.UT_Id,
        }
    })
    .then((res)=>{
        if(res.data>0){
            alert('添加成功');
        }else{
            alert('添加失败');
        }
    })
    .catch((err)=>{
        console.log(err);
    })
}

</script>
